<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display-el" %>
<%@ taglib uri="ford-arg/tags" prefix="ft" %>

<SCRIPT language="JavaScript" 
        src="./scripts/CalendarPopup.js">
</SCRIPT>


<script language="javascript">
	var cal = new CalendarPopup(); 
	cal.showNavigationDropdowns();
	cal.setMonthNames('<bean:message key="label.month.january"/>',
						'<bean:message key="label.month.february"/>',
						'<bean:message key="label.month.march"/>',
						'<bean:message key="label.month.april"/>',
						'<bean:message key="label.month.may"/>',
						'<bean:message key="label.month.june"/>',
						'<bean:message key="label.month.july"/>',
						'<bean:message key="label.month.august"/>',
						'<bean:message key="label.month.september"/>',
						'<bean:message key="label.month.october"/>',
						'<bean:message key="label.month.november"/>',
						'<bean:message key="label.month.december"/>');
	cal.setDayHeaders('<bean:message key="label.day.sunday.capital"/>',
						'<bean:message key="label.day.monday.capital"/>',
						'<bean:message key="label.day.tuesday.capital"/>',
						'<bean:message key="label.day.wednesday.capital"/>',
						'<bean:message key="label.day.thursday.capital"/>',
						'<bean:message key="label.day.friday.capital"/>',
						'<bean:message key="label.day.saturday.capital"/>');
	cal.setTodayText('<bean:message key="label.today"/>');
	
	function findParts() {
		document.PartForm.action = "PartActionFind.do";
		document.PartForm.section.value = "find";
		document.PartForm.editBlocked.value = "false";
		document.PartForm.submit();
	}

	function editPart(rowNum) {
		document.PartForm.action = "PartActionEdit.do";
		document.PartForm.section.value = "edit";
		document.PartForm.editBlocked.value = "true";
		document.PartForm.selectedRowNum.value = rowNum;
		
	}
	
	function createUpdatePart() {
		document.PartForm.action = "PartActionCreateUpdate.do";
		document.PartForm.section.value = "createUpdate";
		document.PartForm.submit();
	}
	
	function deletePart(rowNum) {
		if (confirm('<bean:message key="part.confirmDelete" /> ')) {
			document.PartForm.action = "PartActionDelete.do";
			document.PartForm.section.value = "delete";
			document.PartForm.selectedRowNum.value = rowNum;
		}else{
			return false;
		}
	}
	
	function cleanCreateFields(){
		document.PartForm.action = "PartActionClear.do";
		document.PartForm.section.value = "clean";
		document.PartForm.editBlocked.value = "false";
		document.PartForm.submit();
	}
	
	function clearFindFilds(){
		document.PartForm.action = "PartActionClearFind.do";
		document.PartForm.section.value = "cleanFind";
		document.PartForm.submit();		
		
	}
	
	function cascadeDelete(confirmCascadeDelete){
		if(confirmCascadeDelete){
			document.PartForm.action = "PartActionDelete.do";
			document.PartForm.section.value = "delete";
			document.PartForm.editBlocked.value = "false";
			document.PartForm.confirmCascadeDelete.value = "true";
			document.PartForm.showConfirmCascadeDelete.value = "false";
			document.PartForm.submit();
		}else{
			document.PartForm.confirmCascadeDelete.value = "false";
			document.PartForm.showConfirmCascadeDelete.value = "false";
			findParts();
		}
	}
	function selectOne(num){
		for(i=0; i<document.PartForm.elements.length; i++){
			var name = document.PartForm.elements[i].name.split('(');
			if(name[0]=='seleccMapped'){
				if(name[1].split(')')[0] != num)
				document.PartForm.elements[i].checked=false;
			}
		}
		document.PartForm.selectedRowNum.value = num;
	}
	
	function goSupplyByPart(){
	if(document.PartForm.selectedRowNum.value != ""){
		document.PartForm.action = "PartActionGoSupply.do";
		document.PartForm.submit();
		}
	}
	
	function goPricingByPart(){
		if(document.PartForm.selectedRowNum.value != ""){
			document.PartForm.action = "PartActionGoPricing.do";
			document.PartForm.submit();
		}
	}
	
	function goMixByPart(){
		if(document.PartForm.selectedRowNum.value != ""){
			document.PartForm.action = "PartActionGoMix.do";
			document.PartForm.submit();
		}
	}
	
</script>
	
<table>
	<tr>
		<td colspan="2"><h2><bean:message key="part.label.title"/></h2></td>
	</tr>
</table>
<br/>
<html:form action="/PartActionFind">
<html:hidden property="section" />
<html:hidden property="editBlocked"/>
<html:hidden property="selectedRowNum"/>
<html:hidden property="confirmCascadeDelete"/>
<html:hidden property="showConfirmCascadeDelete"/>

	<%-- Mantiene el numero de pagina despues del submit --%>
	<ft:saveActivePageNumber/>
	
	<bean:define id="nameTitle">
		<bean:message key="part.label.tableHeader.description" />
	</bean:define>
	<bean:define id="partTitle">
		<bean:message key="part.label.tableHeader.part" />
	</bean:define>
	<bean:define id="unitTitle">
		<bean:message key="part.label.tableHeader.unitsMesure" />
	</bean:define>
	<bean:define id="lowComTitle">
		<bean:message key="part.label.tableHeader.lowCom" />
	</bean:define>
	<bean:define id="fechaInTitle">
		<bean:message key="part.label.tableHeader.fechaIn" />
	</bean:define>
	<bean:define id="fechaOutTitle">
		<bean:message key="part.label.tableHeader.fechaOut" />
	</bean:define>
	<bean:define id="creationTitle">
		<bean:message key="label.created" />
	</bean:define>
	<bean:define id="modificationTitle">
		<bean:message key="label.updated" />
	</bean:define>
	<bean:define id="actionsTitle">
		<bean:message key="part.label.tableHeader.actions" />
	</bean:define>
	<bean:define id="edit">
		<bean:message key="label.update" />
	</bean:define>
	<bean:define id="delete">
		<bean:message key="label.delete" />
	</bean:define>
	<bean:define id="selectTitle">
		<bean:message key="label.select" />
	</bean:define>
	<table style="width: 95%;" class="no_border">
		<tr>
			<td class="text_blue_bold align_left" colspan="1">
				<bean:message key="part.label.filter" />
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="part.label.supplier" />
			</td>
			<td>
				<html:select property="supplierClass" styleId="supplierClass">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="partClassColl"
								  property="value"
								  labelProperty="label" />
				</html:select>
			</td>
			<td class="align_left">
				<html:text styleId="supplierCode" property="supplierCode" maxlength="6" size="9"/>
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="part.label" />
			</td>
			<td>
				<html:select property="partClassFind">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="partClassColl"
								  property="value"
								  labelProperty="label" />
				</html:select>
			</td>
			<td class="align_left">
				<html:text styleId="prefixFind" property="prefixFind" maxlength="10" size="9"/>
			</td>
			<td class="align_left">
				<html:text styleId="baseFind" property="baseFind" maxlength="10" size="9"/>
			</td>
			<td class="align_left">
				<html:text styleId="suffixFind" property="suffixFind" maxlength="10" size="9"/>
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left" colspan="1">
				<bean:message key="part.label.dateInBetween" />
			</td>
			<td class="text_blue_bold align_left"  colspan="3">
			    <html:text styleId="dateInMin" property="dateInMin" maxlength="10" size="10"/><A name="dateInMinAnchor"> </A><html:button property="calendar" onclick="cal.select(document.PartForm.dateInMin,'dateInMinAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>
				<bean:message key="label.and" />
				<html:text styleId="dateInMax" property="dateInMax" maxlength="10" size="10"/><A name="dateInMaxAnchor"> </A><html:button property="calendar" onclick="cal.select(document.PartForm.dateInMax,'dateInMaxAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>
			</td>
			<td class="text_blue_bold align_left" colspan="1">
				<bean:message key="part.label.dateOutBetween" />
			</td>
			<td class="text_blue_bold align_left"  colspan="3">
				<html:text styleId="dateOutMin" property="dateOutMin" maxlength="10" size="10"/><A name="dateOutMinAnchor"> </A><html:button property="calendar" onclick="cal.select(document.PartForm.dateOutMin,'dateOutMinAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>
				<bean:message key="label.and" />
				<html:text styleId="dateOutMax" property="dateOutMax" maxlength="10" size="10"/><A name="dateOutMaxAnchor"> </A><html:button property="calendar" onclick="cal.select(document.PartForm.dateOutMax,'dateOutMaxAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>				
			</td>
			<td class="align_right">			
				<input type="button" value="<bean:message key="label.clean"/>" class="button_small" onclick="clearFindFilds();" />
			</td>
			<td class="align_left">
				<html:button property="find" onclick="findParts();" styleClass="button_small"><bean:message key="label.find" /></html:button>
			</td>
		</tr>		
	</table>
	<br/>
	
	<div class="edit_out align_center" style="width:90%;" >
	<div class="edit align_center" style="width: 90%;" >
		<table style="width: 90%;" class="no_border">
			<tr>
				<td class="text_blue_bold align_left" colspan="2">
					<bean:message key="part.label" />
				</td>
				<td class="align_left">
					<logic:equal name="PartForm" property="partClass" value="F">
						<bean:message key="part.label.ford" />
					</logic:equal>
					<logic:notEqual name="PartForm" property="partClass" value="F">
						<bean:message key="part.label.custom" />
					</logic:notEqual>
				</td>
				<td class="align_center">
					<logic:equal name="PartForm" property="editBlocked" value="true">
						<bean:write name="PartForm" property="prefix"/>					
					</logic:equal>
					<logic:notEqual name="PartForm" property="editBlocked" value="true">
						<html:text styleId="prefix" property="prefix" maxlength="10" size="10"/>					
					</logic:notEqual>
				</td>
				<td class="align_center">
					<logic:equal name="PartForm" property="editBlocked" value="true">
						<bean:write name="PartForm" property="base"/>					
					</logic:equal>
					<logic:notEqual name="PartForm" property="editBlocked" value="true">
						<html:text styleId="base" property="base" maxlength="10" size="10"/>					
					</logic:notEqual>
				</td>
				<td class="align_center">
					<logic:equal name="PartForm" property="editBlocked" value="true">
						<bean:write name="PartForm" property="suffix"/>					
					</logic:equal>
					<logic:notEqual name="PartForm" property="editBlocked"value="true">
						<html:text styleId="suffix" property="suffix" maxlength="10" size="10"/>					
					</logic:notEqual>
				</td>
				<td class="text_blue_bold align_left">
					<bean:message key="part.label.tableHeader.description" />
				</td>
				<td class="align_left" colspan="4">
					<html:text styleId="name" property="name" maxlength="50" size="50"/>					
				</td>
				<td >
					<html:button styleClass="button_small" property="update" onclick="createUpdatePart();"><bean:message key="label.createUpdate" /></html:button>
				</td>
			</tr>
			<tr>
				<td class="text_blue_bold align_left" colspan="2">
					<bean:message key="part.label.tableHeader.unitsMesure" />
				</td>
				<td class="align_center" colspan="1">
					<html:text styleId="unitsMesure" property="unitsMesure" maxlength="3" size="5"/>					
				</td>
				<td colspan="2"/>
				<td class="text_blue_bold align_left" >
					<bean:message key="part.label.tableHeader.lowCom" />
				</td>
				<td class="align_left" colspan="1">
					<html:text styleId="lowCom" property="lowCom" maxlength="5" size="7"/>					
				</td>
				<td colspan="4"/>
				<td class="text_blue_bold align_center">
					<input type="button" value="<bean:message key="label.new"/>" class="button_small" onclick="javascript:cleanCreateFields()" />			
				</td>											
			</tr>
			<tr>
				<td class="text_blue_bold align_left" colspan="2">
					<bean:message key="part.label.tableHeader.fechaIn" />
				</td>
				<td class="align_left" colspan="2">
					<html:text styleId="fechaIn" property="fechaIn" maxlength="10" size="12"/><A name="dateInAnchor"> </A><html:button property="calendar" onclick="cal.select(document.PartForm.fechaIn,'dateInAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>
				</td>
				<td class="text_blue_bold align_left">
					<bean:message key="part.label.tableHeader.fechaOut" />
				</td>
				<td class="align_left" colspan="3">
					<html:text styleId="fechaOut" property="fechaOut" maxlength="10" size="12"/><A name="dateOutAnchor"> </A><html:button property="calendar" onclick="cal.select(document.PartForm.fechaOut,'dateOutAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>
				</td>
				<td class="text_blue_bold align_left">
					<bean:message key="part.label.tableHeader.commodity" />&nbsp;
					<html:select property="partCommodity">
						<html:option value="-1"><bean:message key="label.allOption" /></html:option>
						<html:options collection="commColl"
								  property="eesp02CommodityNumberK"
								  labelProperty="eesp02CommodityNameN" style="heigth=10"/>
					</html:select>
				</td>
				<td class="align_left" colspan="1">
					
				</td>
				<td colspan="4"/>
			</tr>
		</table>
	</div>
	</div>	
	
	<br/>
	<div class="align_left" style="width:90%;" >
		<table class="no_border">
			<tr>
				<td><html:button property="supp" styleClass="button" style="width:120px;" onclick="goSupplyByPart()" ><bean:message key="part.label.suppliers&TVM"/></html:button></td>
				<td><html:button property="yes" styleClass="button" style="width:60px;" onclick="goPricingByPart()" ><bean:message key="part.label.pricing"/></html:button></td>
				<td><html:button property="yes" styleClass="button" style="width:60px;" onclick="goMixByPart()" ><bean:message key="part.label.mix&PU"/></html:button></td>
			</tr>
		</table>
	</div>
	<logic:equal name="PartForm" property="showConfirmCascadeDelete" value="true">
		<div class="messagescontent_error align_center" style="width:400px;" >
			<table class="messages" cellspacing="0">
				<tr>
					<td class="messagescontent_error" colspan="2"><bean:message key="part.confirmCascadeDelete"/></td> 
				</tr > 
				<tr>
					<td class="messagescontent_error" align="center"><html:button property="yes" styleClass="button_small" style="width:50px;" onclick="cascadeDelete(true);" ><bean:message key="label.yes"/></html:button></td>
					<td class="messagescontent_error" align="center"><html:button property="yes" styleClass="button_small" style="width:50px;" onclick="cascadeDelete(false);" ><bean:message key="label.no"/></html:button></td>
				</tr>
			</table>
		</div>
	</logic:equal>	
	
	<table class="no_border" style="width: 90%;">
		<tr>
			<td>
				<display-el:table 	class="table1" style="width: 100%;" cellpadding="5" uid="part"
									 pagesize="15" name="sessionScope.PartForm.parts" 
									excludedParams="*" requestURI="PartActionPaginate.do" >
					<display-el:column title="${partTitle}" style="width: 18%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
						<bean:write name="part" property="eesp01PartClassCodeC"/>
						<bean:write name="part" property="eesp01PartPrefixCodeC"/>&minus;<bean:write name="part" property="eesp01PartBaseCodeC"/>&minus;<bean:write name="part" property="eesp01PartSuffixCodeC"/>
					</display-el:column>
					<display-el:column title="${nameTitle}" property="eesp01PartDescriptionX" style="width: 15%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right"/>
					<display-el:column title="${unitTitle}" property="eesp01PartUnitmeasureCodeC" style="width: 6%;" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right"/>
					<display-el:column title="${lowComTitle}" style="width: 6%;" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
						<logic:empty name="part" property="eesp01PartCommodLowCodeC">-</logic:empty>
						<logic:notEmpty name="part" property="eesp01PartCommodLowCodeC">
							<bean:write name="part" property="eesp01PartCommodLowCodeC"/>
						</logic:notEmpty>
					</display-el:column>
					<display-el:column title="${fechaInTitle}" property="eesp01PartInDateY" decorator="ar.com.ford.it.fullEconomics.view.displaytag.DateDecorator"  style="width: 10%;"  class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right" />
					<display-el:column title="${fechaOutTitle}" property="eesp01PartOutDateY" decorator="ar.com.ford.it.fullEconomics.view.displaytag.DateDecorator"  style="width: 10%;"  class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right" />
					<display-el:column title="${creationTitle}" style="width: 12%;"  decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right" >
						<bean:write name="part" property="eesp01CreateUserC"/><br />
						<bean:write name="part" property="eesp01CreateS"/>
					</display-el:column>
					<display-el:column title="${modificationTitle}" style="width: 12%;"  decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right" >
						<bean:write name="part" property="eesp01LastUpdtUserC"/><br />
						<bean:write name="part" property="eesp01LastUpdtS"/>
					</display-el:column>
					<display-el:column title="${actionsTitle}"  style="width: 10%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
						<logic:equal name="part" property="eesp01PartClassCodeC" value="C">
							<html:image property="" alt="${edit}"
								onclick="editPart(${part_rowNum});" page="/images/edit.gif"
								style="width:20px" />&nbsp;
							<html:image property="" alt="${delete}"
								onclick="deletePart(${part_rowNum});" page="/images/erase.gif"
								style="width:20px" />&nbsp;
						</logic:equal>
						
					</display-el:column>
					<display-el:column title="${selectTitle}"  style="width: 10%;" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
						<html:checkbox property="seleccMapped(${part_rowNum})" onclick="selectOne(${part_rowNum});"></html:checkbox>
					</display-el:column>
				</display-el:table>
			</td>		
		</tr>
	</table>
	<DIV ID="calDiv" STYLE="position:absolute;visibility:hidden;background-color:white;layer-background-color:white;"></DIV>
</html:form>